#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File __init__.py
 * Created by leixu on 2017/11/9
 * IDE PyCharm
'''


class BaseParamGetter(object):
    def __init__(self):
        pass


import redis


class RedisParamGetter(BaseParamGetter):
    def __init__(self):
        super(RedisParamGetter, self).__init__()
        self.key = None

        self.config = None
        self.redis: redis.StrictRedis = None

    def load_config(self, config: dict):
        self.key = config["key"]
        self.config = {"host": config["host"], "port": config["port"], "password": config["password"], "db": config["db"]}
        self.redis = redis.StrictRedis(**self.config)

    def get(self):
        return self.redis.lpop(self.key)


if __name__ == "__main__":
    getter = RedisParamGetter()
    config = {'key': 'xHOPZKHWbL9Ryy5x7pAF8L', 'host': '192.168.2.24', 'port': 6379, 'password': 'bigdata', 'db': 1}
    getter.load_config(config)
    print(getter.get())
